package com.chinda.common.utils;

import com.chinda.common.security.SysUserDetails;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Security工具类
 *
 * @author Wang Chinda
 * @date 2020/7/11
 * @see
 * @since 1.0
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SecurityUtil {

    /**
     * 获取当前用户信息
     */
    public static SysUserDetails getUserDetail(){
        return (SysUserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();
    }
    /**
     * 获取当前用户ID
     */
    public static Long getUserId(){
        return getUserDetail().getUserId();
    }
    /**
     * 获取当前用户账号
     */
    public static String getUserName(){
        return getUserDetail().getUsername();
    }
}